package ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public abstract class NO_TRIM_MOVABLE_SHELL extends Shell implements MouseListener, MouseMoveListener{

	private boolean isDrag = false;
	private int mouseLastX;
	private int mouseLastY;
	private int mouseStartX;
	private int mouseStartY;
	
	public NO_TRIM_MOVABLE_SHELL(int style) {
		super(SWT.NO_TRIM);
		initail();
	}
	
	public NO_TRIM_MOVABLE_SHELL(Display display, int style) {
		super(display, SWT.NO_TRIM);
		initail();
	}
	
	public NO_TRIM_MOVABLE_SHELL(Display display) {
		super(display, SWT.NO_TRIM);
		initail();
	}
	public NO_TRIM_MOVABLE_SHELL(Shell parent) {
		super(parent, SWT.NO_TRIM);
		initail();
	}
	public NO_TRIM_MOVABLE_SHELL(Shell parent, int style) {
		super(parent, style);
		initail();
	}
	
	private void initail() {
		addMouseMoveListener(this);
		addMouseListener(this);
	}
	
	@Override
	protected void checkSubclass() {
	}
	
	@Override
	public void mouseMove(MouseEvent e) {
		if (isDrag) {

			mouseLastX = e.x;
			mouseLastY = e.y;
			int x = mouseLastX - mouseStartX;
			int y = mouseLastY - mouseStartY;
			Point location = this.getLocation();
			int xx = location.x;
			int yy = location.y;
			this.setLocation(x + xx, y + yy);
		}
	}

	@Override
	public void mouseDoubleClick(MouseEvent e) {}

	@Override
	public void mouseDown(MouseEvent e) {
		isDrag = true;
		mouseStartX = e.x;
		mouseStartY = e.y;
	}

	@Override
	public void mouseUp(MouseEvent e) {
		isDrag = false;
	}
}
